import React, { useState, useEffect } from 'react'
import AForm from "../../compent/AForm"
import { AformConfig, tableColumns, tableData } from "./config/index"
import ATable from "../../compent/ABtate"
import { pageList } from "../../untils/api"

export default function Page() {
  const [pageSizes, setPageSize] = useState(10)
  const [page, setPage] = useState(1)
  const [total, settotal] = useState(0)
  const [data, setData] = useState([])
  const [fromobj, setFeomObj] = useState<object>({})

  useEffect(() => {
    getList(page)
  }, [])
  const getList = (page: number, pageSize: number = pageSizes, Fromobj: object = fromobj) => {
    const params = {
      page,
      pageSize: pageSize,
      ...Fromobj
    }
    console.log(params)
    pageList.getPageList(params).then(res => {
      console.log(res.data.data[0])
      console.log(res.data.data[1])
      //列表
      setData(res.data.data[0])
      //总数据
      settotal(res.data.data[1])
    })

  }
  const onPageSize = (pageNumber: number, pageSize: number) => {
    console.log(pageNumber, pageSize, "从子组件获取")
    setPage(pageNumber)
    setPageSize(pageSize)
    getList(pageNumber, pageSize)
  }
  const submit = (data: any) => {
    // console.log(data)
    // getList(page,data)
    setFeomObj(data)
    //调用接口
    getList(page, pageSizes, data)

  }
  //重置
  const onResetFields=()=>{
    getList(page, pageSizes, {})
  }
 //编辑
  const edit = (record:any, status:any) => {
    console.log(record, status)

  }
   //设置发布线下
  const setStatus = (record:any, status:any) => {
    console.log(record, status)
    if(status==="publish"){
      status="draft"
    }else{
      
    }

  }
  //查看访问
  const Find = (record:any, status:any) => {
    console.log(record, status)
  }
  //删除
  const Del = (record:any, status:any) => {
    console.log(record, status)
  }
  return (
    <div>
      页面管理
      <AForm onsubmit={submit} onResetFields={onResetFields} AformConfig={AformConfig}></AForm>

      {/* edit: (record:any, status:any) => void,
    setStatus: (record:any, status:any) => void,
    Find: (record:any, status:any) => void,
    Del: (record:any, status:any) => void) */}
      <ATable
        total={total}
        page={page}
        pageSize={pageSizes}
        onchange={onPageSize}
        columns={tableColumns(edit, setStatus, Find,Del)}
        data={data}></ATable>
    </div>

  )
}
